<template>
  <gui-page ref="guiPage" :customHeader="true">
    <!-- 导航 -->
    <template v-slot:gHeader>
      <nav-bar-custom left-icon="left" :leftType="'1'" @clickLeftBack="clickLeftBack"
        :title="$t('translationImage.FGIn-storage')" @clickRight="clickRight" scanType="1"></nav-bar-custom>
    </template>

    <template v-slot:gBody>
      <view class="barcodeSplitting">
        <!-- 扫描和库位选择模块 -->
        <view class="custom-form-card">
          <view class="custom-card-title">
            <text class="title-line"></text>
            {{ $t('translationImage.In-storageInfo') }}
          </view>
          <view class="custom-card-itemTwo" style="padding: 10rpx 0">
            <text class="item-info-title">{{ $t('distributedOut.warehouse') }}：</text>
            <input type="text" disabled style="margin: 8rpx 0;text-align: right;" class="gui-form-input"
              v-model="data.warehouse" :placeholder="$t('hardwareOut.pleaseScanMaterial')" />
          </view>
          <!-- 库位选择加开关 -->
          <view class="custom-card-itemTwo" style="padding: 20rpx 0">
            <text class="item-info-title">
              <text class="required-color">*</text>{{ $t('warehousing.recommendLocation') }}：
            </text>
            <uni-data-select :disabled="data.isChecked" v-model="data.locationCode" :localdata="data.range"
              :clear="false" @change="change"></uni-data-select>
            <switch :checked="data.isChecked" style="transform:scale(0.7)" @change="switchChange"
              :disabled="!data.locationCode" />
            <view>{{ data.isChecked ? $t('mexico.lock') : $t('mexico.unLock') }}</view>
          </view>
          <view class="custom-card-itemTwo" style="padding: 16rpx 0;">
            <text class="item-info-title" style="padding-right: 40rpx;">
              <text class="required-color">*</text>{{ $t('distributedEnter.barcodeScan') }}
            </text>
            <uni-easyinput class="uni-mt-5" :disabled="!data.isChecked" suffixIcon="scan" v-model="data.barcode"
              type="search" @confirm="confirm" @iconClick="iconClick"
              :placeholder="$t('pageTranslation.plsScanBarcodeOr')">
            </uni-easyinput>
          </view>
          <view class="custom-card-itemTwo" style="padding:10rpx 0"
            v-if="data.sizeShow == '48' || data.sizeShow == '' || data.sizeShow == '0'">
            <text class="item-info-title">{{ $t('mexico.dischargeQty') }}：</text>
            <input type="text" disabled style="margin: 8rpx 0;text-align: right;" class="gui-form-input"
              v-model="data.currentCapacitys" />
          </view>
          <view class="custom-card-itemTwo" style="padding: 10rpx 0"
            v-if="data.sizeShow == '60' || data.sizeShow == '' || data.sizeShow == '0'">
            <text class="item-info-title">{{ $t('mexico.dischargeQty2') }}：</text>
            <input type="text" disabled style="margin: 8rpx 0;text-align: right;" class="gui-form-input"
              v-model="data.currentCapacitys2" />
          </view>
        </view>
        <!-- 汇总数据 -->
        <view class="card-boxCustom gui-transition-all  defective-box" style="margin: 20rpx 20rpx 0;"
            v-if="data.list.length">
						<uni-collapse v-model="data.collectShow" style="padding-bottom: 20rpx;" >
							<uni-collapse-item titleBorder="none" :show-animation="true">
								<template v-slot:title>
									<view class="custom-card-title">
										<text class="title-line"></text>
										{{ $t('materials.summaryOfMaterials') }}
									</view>
								</template>
								<uni-card class="card-my" style="" @click="clickRight">
                  <uni-table border stripe emptyText="暂无更多数据" style="max-height: 400rpx;box-sizing: border-box;">
										<!-- 表头行 -->
										<uni-tr class="tableLineHeight">
											<uni-th class="tableLine" width="100">{{ $t("distributedEnter.materialCode")
												}}</uni-th>
											<uni-th class="tableLine" width="100">{{ $t("distributedEnter.qty")
												}}</uni-th>
                      <uni-th class="tableLine" width="100">{{ $t("translationImage.numberOfBarcodes")
												}}</uni-th>
										</uni-tr>
										<!-- 表格数据行 -->
										<uni-tr class="tableLineHeight" v-for="(x, i) in data.list" :key="i">
											<uni-td class="tableLine">{{ x.materialCode }}</uni-td>
											<uni-td class="tableLine">{{ x.total }}</uni-td>
                      	<uni-td class="tableLine">{{ x.collect }}</uni-td>
										</uni-tr>
                  </uni-table>
                </uni-card>
              </uni-collapse-item>
            </uni-collapse>
          </view>
        <!-- card模块 -->
        <!-- <scroll-view :show-scrollbar="false" :scroll-y="true" class="scroll"> -->
        <view v-if="data.scanInfo" class="custom-form-card">
          <uni-collapse v-model="data.value">
            <uni-collapse-item titleBorder="none" :show-animation="true">
              <template v-slot:title>
                <view class="custom-card-title">
                  <text class="title-line"></text>
                  {{ $t('distributedOut.atPresent') }}
                </view>
              </template>
              <view class="content">
                <view class="custom-card-itemOne">
                  <text class="item-info-title">{{ $t('distributedEnter.materialCoded') }}：
                  </text>
                  {{ data.scanInfo.barcode }}
                </view>
                <view class="custom-card-itemOne">
                  <text class="item-info-title">{{ $t('distributedEnter.materialCode') }}：
                  </text>
                  {{ data.scanInfo.materialCode }}
                </view>
                <view class="custom-card-itemOne">
                  <text class="item-info-title">{{ $t('distributedEnter.materialName') }}：
                  </text>
                  {{ data.scanInfo.materialName }}
                </view>
                <view class="custom-card-itemOne">
                  <text class="item-info-title">{{ $t('distributedEnter.materialSpec') }}：
                  </text>
                  {{ data.scanInfo.materialSpec }}
                </view>
                <view class="custom-card-itemOne">
                  <view class="card-item-50">
                    <text class="item-info-title">{{ $t('distributedEnter.qty') }}：
                    </text>
                    {{ data.scanInfo.currentQty }}
                  </view>
                  <view class="card-item-50">
                    <text class="item-info-title">{{ $t('distributedEnter.uom') }}：
                    </text>
                    {{ data.scanInfo.unit }}
                  </view>
                </view>
              </view>
            </uni-collapse-item>
          </uni-collapse>
        </view>
        <!-- </scroll-view> -->
        <!-- 底部确定按钮 -->
        <view class="page-bottom-boxtwo">
          <view class="page-bottomBtn bottomBtn-bgcolor-green" @click="handelCommit">
            {{ $t('translationImage.storage') }}
          </view>
        </view>
      </view>
    </template>
  </gui-page>
</template>

<script setup>
import { navigate } from '@/utils/routerSkip.js';
import pdaScan from '@/hooks/pdaScan.js'
import { useStore } from "vuex";
import storageBin from '@/components/storageBin.vue'
import { pdaRecommendLocation, pdaLockLocation, instockBarcodeDetail, getDataDictionary, pdaSubmitInstock } from '@/api/api.js'
import { basPdaOperationLogFn } from '@/utils/index.js';
import { OPERATION_COMMIT, OPERATION_LOOK, OPERATION_SCAN } from '@/constant/index.js'
import { ref, reactive, onMounted, watch, computed, toRaw } from 'vue';
import { onBackPress } from '@dcloudio/uni-app';
//JS国际化引入
import { useI18n } from 'vue-i18n';

const { t } = useI18n();
const { scan } = pdaScan()
components: {
  storageBin
}
const storageBinRef = ref(null)

let data = reactive({
  requestBool: false, //库位是否直接请求的标识
  defaultValue: '', //默认库位
  value: ['0'],
  warehouse: t('pageTranslation.warehouseOfFG'), //仓库
  currentLocationInfo: {}, // 当前选择库位信息
  locationUseList: [], //
  isChecked: false,// 是否选中
  range: [],
  lockStatus: '', //锁定状态
  scanInfo: undefined, //当前扫描数据
  locationCode: '', //仓库 locationCode
  barcodeList: [],
  seat: '', //库位
  barcode: '', //条码
  ignoreLocationCode: [], //前端算满的库位
  currentTotal: null, //当前总容量  48英寸
  currentTotal2: null, //当前总容量   60英寸
  currentCapacitys: null, // 当前剩余容量 48英寸
  currentCapacitys2: null, // 当前剩余容量  60英寸
  firstLocation: true, //第一次请求库位
  totalQty: null, //当前最大容量
  totalQty2: null, //当前最小容量
  positionQty: null,
  dimensionList: [], // 托盘尺寸吧绑定物料
  sizeShow: '',
  list:[],//汇总数据存储
})
/**
 * 1.默认为成品仓
 * 2.库位为成品仓下面的库位 接口传
 * 3.判断当前扫码是否属于成品仓
 * 4.扫码输入数量是否超出库位容量
 */
let store = useStore();

onMounted(() => {
  console.log('开始监听PDA扫码')
  uni.$on('scancodedate', (data) => {
    console.log('获取到的code：' + data.code)
    getCode(data.code, 'pda')
  })
  changeLocation()
  sinishMaterialPalletSize()
  uni.$on('addInventoryCount', () => {
    data.currentCapacitys = Number(data.currentTotal) - data.barcodeList.length;
  })
  try {
    let inputParameter = '无'
    let returnParameter = '无'
    let operationPicture = '成品入库'
    let callInterface = '无'
    let opertionParmes = {
      inputParameter,
      returnParameter,
      operationPicture,
      callInterface,
      responseCode: '无', //返回状态
      errorMessage: '无', //错误信息
      isPass: 'Y', //是否成功 Y N
      operationType: OPERATION_LOOK,
      module: 'WMS',
      source: "PDA",
    }
    basPdaOperationLogFn(opertionParmes)
  } catch (error) {
  }
})


// 推荐库位获取
const changeLocation = () => {
  pdaRecommendLocation().then(res => {
    try {
      let inputParameter = JSON.stringify('无')
      let returnParameter = JSON.stringify(res)
      let operationPicture = '成品入库'
      let callInterface = res.rquestUrl
      let opertionParmes = {
        inputParameter,
        returnParameter,
        operationPicture,
        responseCode: res.code, //返回状态
        errorMessage: res.msg, //错误信息
        isPass: res.code == 0 ? 'Y' : 'N', //是否成功 Y N
        callInterface,
        operationType: OPERATION_LOOK,
        module: 'WMS',
        source: "PDA",
      }
      basPdaOperationLogFn(opertionParmes)
    } catch (error) {
    }
    if (res.code == 0) {
      res.data.forEach(item => {
        item.text = item.locationCode
        item.value = item.locationCode
        item.id = item.locationId
      })
      data.range = res.data
      // data.range.push({ text: 'FG001', value: 'FG001', maxCapacity: 30, minCapacity: 20, usedInventory: 2 })
      // data.range.push({ text: 'FG002', value: 'FG002', maxCapacity: 30, minCapacity: 20, usedInventory: 2 })
    }
  })
}
// 库位选择
const change = (e) => {
  data.locationCode = e
  // 选择库位后去查询选择的库位的剩余数量
  let arr = data.range.filter(x => x.value == e);
  console.log(arr)
  // 选择的库位赋值给list
  if (arr[0].lockStatus == 'lock') {
    data.isChecked = true
  }
  data.sizeShow = arr[0].attribute1 || ''
  data.locationUseList = arr
  data.currentLocationInfo = arr[0]
  data.totalQty = data.locationUseList[0].maxCapacity; // 最大容量
  data.totalQty2 = data.locationUseList[0].maxCapacity;// 最大容量

  data.currentTotal = data.locationUseList[0].maxCapacity - data.locationUseList[0].usedInventory  // 当前剩余总容量
  data.currentTotal2 = data.locationUseList[0].minCapacity - data.locationUseList[0].usedInventory  // 当前剩余总容量

  data.currentCapacitys = data.locationUseList[0].maxCapacity - data.locationUseList[0].usedInventory; // 当前剩余容量
  data.currentCapacitys2 = data.locationUseList[0].minCapacity - data.locationUseList[0].usedInventory;// 当前剩余容量

  judgeBarcode()
  if (data.locationCode) {
    //全局消息总线
    uni.$emit('reduceInventoryCount', {
      locationId: data.locationCode,
      count: data.barcodeList.length
    })
  }
}

//数据字典获取成品物料托盘尺寸并在扫描条码的时候做比较
const sinishMaterialPalletSize = () => {
  getDataDictionary({ code: 'FinishMaterialPalletSize' }).then(res => {
    data.dimensionList = res.data
  })
}

// 开关切换 锁定、解锁
const switchChange = (e) => {
  // console.log(e.detail.value)
  data.isChecked = e.detail.value
  if (data.isChecked) {
    data.lockStatus = 'lock'
  } else {
    data.lockStatus = 'unLock'
  }
  if (data.lockStatus == 'unLock' && data.barcodeList.length) {
    uni.showModal({
      title: t('Common.prompt'),
      content: t('mexico.unlockingBarcode'),
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定');
          store.commit('reactFinishedProductStorage')
        } else if (res.cancel) {
          return
        }
      }
    });
  }
  // 点击锁定调用接口
  let parmes = {
    locationCode: data.locationCode,
    lockStatus: data.lockStatus
  }

  // 锁定的时候给提示
  if (data.lockStatus == 'lock') {
    uni.showModal({
      title: t('Common.prompt'),
      content: t('taskList.lockLocation'),
      success: function (res) {
        if (res.confirm) {
          pdaLockLocation(parmes).then(res => {
            try {
              let inputParameter = JSON.stringify(parmes)
              let returnParameter = JSON.stringify(res)
              let operationPicture = '成品入库'
              let callInterface = res.rquestUrl
              let opertionParmes = {
                inputParameter,
                returnParameter,
                operationPicture,
                responseCode: res.code, //返回状态
                errorMessage: res.msg, //错误信息
                isPass: res.code == 0 ? 'Y' : 'N', //是否成功 Y N
                callInterface,
                operationType: OPERATION_SCAN,
                module: 'WMS',
                source: "PDA",
              }
              basPdaOperationLogFn(opertionParmes)
            } catch (error) {
            }
            if (res.code == 0) {
              if (data.lockStatus == 'lock') {
                uni.showToast({
                  title: t('mexico.lockSuccess'),
                  icon: 'none'
                })
              } else {
                uni.showToast({
                  title: t('mexico.unLockSuccess'),
                  icon: 'none'
                })
              }
            } else {
              // 调用接口失败后还原
              data.isChecked = !data.isChecked
              uni.showToast({ title: res.msg, icon: 'none' })
            }
          })

        } else if (res.cancel) {
          data.lockStatus = 'unLock'
          data.isChecked=false
          return
        }
      }
    });
  } else {

    pdaLockLocation(parmes).then(res => {
      try {
        let inputParameter = JSON.stringify(parmes)
        let returnParameter = JSON.stringify(res)
        let operationPicture = '成品入库'
        let callInterface = res.rquestUrl
        let opertionParmes = {
          inputParameter,
          returnParameter,
          operationPicture,
          responseCode: res.code, //返回状态
          errorMessage: res.msg, //错误信息
          isPass: res.code == 0 ? 'Y' : 'N', //是否成功 Y N
          callInterface,
          operationType: OPERATION_SCAN,
          module: 'WMS',
          source: "PDA",
        }
        basPdaOperationLogFn(opertionParmes)
      } catch (error) {
      }
      if (res.code == 0) {
        if (data.lockStatus == 'lock') {
          uni.showToast({
            title: t('mexico.lockSuccess'),
            icon: 'none'
          })
        } else {
          uni.showToast({
            title: t('mexico.unLockSuccess'),
            icon: 'none'
          })
        }
      } else {
        // 调用接口失败后还原
        data.isChecked = !data.isChecked
        uni.showToast({ title: res.msg, icon: 'none' })
      }
    })

  }
}

data.barcodeList = computed(() => {
  return store.state.finishedProductStorageList
})

// 汇总数据
const collect=(item)=>{
  data.collect = ['0']
	let list = Object.values(item)
	let dataInfo = {};
	list.forEach((item, index) => {
		let { materialCode } = item;
		// 扫描的物料按照物料号分类
		if (!dataInfo[materialCode]) {
			dataInfo[materialCode] = {
				materialCode,
				child: []
			}
		}
		dataInfo[materialCode].child.push(item)
		// 扫描的物料代码分类的总数用量 计算总数
		dataInfo[materialCode].total = dataInfo[materialCode].child.reduce((pre, cur) => {
			return pre + cur.currentQty;
		}, 0)
		// 物料条码个数
		dataInfo[materialCode].collect = dataInfo[materialCode].child.length

	});
	data.list = Object.values(dataInfo);
  console.log(data.list)
}

// 计算库位逻辑
const calculateLocationCode = (newVal) => {
  let tepData = toRaw(newVal)
  if (!tepData.length) {
    data.scanInfo = undefined
    data.barcode = ''
  }
  if (!data.scanInfo && tepData.length) {
    data.scanInfo = tepData[0]
    data.barcode = data.scanInfo.barcode
  }

  data.currentCapacitys = data.currentTotal - tepData.length; // 当前剩余容量
  data.currentCapacitys2 = data.currentTotal2 - tepData.length;// 当前剩余容量
  console.log(data.sizeShow == '48')
  if (data.sizeShow == '48') {
    if (data.currentCapacitys < 0 && data.barcodeList.length && data.currentTotal != null) {
      data.currentCapacitys = 0
      store.commit('deleteFinishedProductStorageByBarcode', data.barcode)
      uni.showToast({
        title: t('JsInternational.volumn'),
        icon: 'none'
      })
      return
    }
  } else if (data.sizeShow == '60') {
    if (data.currentCapacitys2 < 0 && data.barcodeList.length && data.currentTotal2 != null) {
      data.currentCapacitys2 = 0
      store.commit('deleteFinishedProductStorageByBarcode', data.barcode)
      uni.showToast({
        title: t('JsInternational.volumn'),
        icon: 'none'
      })
      return
    }
  }

}

//把扫描条码变为物料集合的二维数组
watch(() => data.barcodeList, (newVal, oldVal) => {
  calculateLocationCode(newVal)
  collect(newVal)
}, {
  immediate: true,
  deep: true
});

// 用户点击扫码图标
const iconClick = async (type) => {
  if (type === 'suffix') {
    let code = await scan()
    getCode(code, 'scan')
  }
}
// 用户点击搜索
const confirm = () => {
  getCode(data.barcode, 'keydown')
}
// 获取code
const getCode = (code, type) => {
  // 判断这个条码是否扫描过
  let arr = data.barcodeList.filter(x => x.barcode == code);
  if (arr.length > 0) {
    uni.showToast({ title: t('smashRemoval.codesRepeatedly'), icon: 'none' });
    return
  }
  let isBind = data.barcodeList.some(x => x.barcode == code);
  if (isBind) {
    uni.showToast({
      title: t('JsInternational.scanned'),
      icon: 'none'
    })
    return
  }
  if (!code) {
    uni.showToast({
      title: t('stockManage.pleaseScanCode'),
      icon: 'none'
    })
    return
  }
  // 判断容量是否为0
  // if ((!data.currentCapacitys) || (!data.currentCapacitys2)) {
  //   uni.showToast({
  //     title: t('JsInternational.volumn'),
  //     icon: 'none'
  //   })
  //   return
  // }
  data.scanValue = code
  let parmes = code
  uni.showLoading({
    title: 'loading',
    mask: true
  });
  data.barcode = code
  instockBarcodeDetail(parmes).then(res => {
    //隐藏加载框
    uni.hideLoading();
    try {
      let inputParameter = JSON.stringify(parmes)
      let returnParameter = JSON.stringify(res)
      let operationPicture = '成品入库'
      let callInterface = res.rquestUrl
      let opertionParmes = {
        inputParameter,
        returnParameter,
        operationPicture,
        responseCode: res.code, //返回状态
        errorMessage: res.msg, //错误信息
        isPass: res.code == 0 ? 'Y' : 'N', //是否成功 Y N
        callInterface,
        operationType: OPERATION_SCAN,
        module: 'WMS',
        source: "PDA",
      }
      basPdaOperationLogFn(opertionParmes)
    } catch (error) {
    }
    if (res.code == 0) {
      // console.log(res)
      // 成品入库每批次只能入库同一种物料
      let materialCode = res.data.materialCode;
      if (data.barcodeList.length == 0) {

      } else {
        var existMaterialCode = data.barcodeList.some(e => e.materialCode == materialCode)
        if (!existMaterialCode) {
          uni.showToast({
            title: t('stockManage.fgInstore'),
            icon: 'none'
          })
          return
        }
      }
      if (data.sizeShow == '0') {
        // 判断扫描的物料托盘尺寸为48还是60
        let sizeArr = data.dimensionList.filter(x => x.text == materialCode)
        data.sizeShow = sizeArr[0].value
      } else if (res.data.attribute1 != data.sizeShow) {
        uni.showToast({
          title: t('mexico.mixing'),
          icon: 'none'
        })
        return
      }
      // 複製
      data.scanInfo = res.data

      // 添加推荐库位和最大最小和已用容量
      data.scanInfo.recommendedLocation = data.locationCode
      data.scanInfo.positionQty = data.positionQty
      data.scanInfo.maxCapacity = data.locationUseList[0].maxCapacity
      data.scanInfo.minCapacity = data.locationUseList[0].minCapacity
      data.scanInfo.usedInventory = data.locationUseList[0].usedInventory

      store.commit('addFinishedProductStorage', data.scanInfo)
    } else {
      // 扫描错误
      uni.showModal({
        title: t('Common.prompt'),
        content: res.msg,
        confirmText: t('translationImage.close'),
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
          } else if (res.cancel) {
          }
        }
      });
      data.barcode = ''
    }
  })
}
// 判断 Barcode
const judgeBarcode = () => {
  let isTrue = data.locationUseList.some(x => x.locationCode === data.locationCode)
  if (!isTrue) {
    data.locationUseList.push({
      locationCode: data.currentLocationInfo.locationCode, //库位code
      surplusCapacity: Number(data.currentLocationInfo.maxCapacity) - Number(data.currentLocationInfo
        .usedInventory), //后端告诉前端容量
      barcodeList: [] //当前库位本次扫描绑定的barcode条码集合
    })
  }

}

// 提交操作
const handelCommit = () => {
  // 1.判断是否有数据
  if (!data.barcodeList.length) {
    uni.showToast({
      title: t('stockManage.pleaseScanCode'),
      icon: 'none'
    })
    return
  }
  if (!data.isChecked) {
    uni.showToast({
      title: t('mexico.locationLockedNo'),
      icon: 'none'
    })
    return
  }

  let parmes = []
  data.barcodeList.forEach(x => {
    console.log(x)
    parmes.unshift({
      barcode: x.barcode,
      locationCode: x.recommendedLocation,
      materialCode: x.materialCode,
      whichNumber: 0,
      agvPointCode: '',
      operatePlatform: 'PDA',
    })
  })
  uni.showLoading({
    title: 'loading',
    mask: true
  });
  pdaSubmitInstock(parmes).then(res => {
    //隐藏加载框
    uni.hideLoading();
    try {
      let inputParameter = JSON.stringify(parmes)
      let returnParameter = JSON.stringify(res)
      let operationPicture = '成品入库'
      let callInterface = res.rquestUrl
      let opertionParmes = {
        inputParameter,
        returnParameter,
        operationPicture,
        callInterface,
        responseCode: res.code,//返回状态
        errorMessage: res.msg,//错误信息
        isPass: res.code == 0 ? 'Y' : 'N',//是否成功 Y N
        operationType: OPERATION_COMMIT,
        module: 'WMS',
        source: "PDA",
      }
      basPdaOperationLogFn(opertionParmes)
    } catch (error) {
    }
    if (res.code == 0) {
      //隐藏加载框
      uni.hideLoading();
      uni.showToast({ title: t('smashRemoval.submitSuccessfully'), icon: "none" });
      //删除已提交的数据
      store.commit('reactFinishedProductStorage')
      data.barcode = ''
      data.currentCapacitys = null
      data.currentCapacitys2 = null
      data.currentTotal = null
      data.currentTotal2 = null
      data.sizeShow = ''
      data.scanInfo = undefined
      uni.showModal({
        title: t('Common.prompt'),
        content: t('taskList.whetherUnlock'),
        confirmText: t('index.yes'),//这块是确定按钮的文字
        cancelText: t('index.no'),//这块是取消的文字
        success: function (res) {
          if (res.confirm) {
            // 确定解锁库位
            data.isChecked = false
            let parmes = {
              locationCode: data.locationCode,
              lockStatus: 'unLock'
            }
            pdaLockLocation(parmes).then(res => {
              try {
                let inputParameter = JSON.stringify(parmes)
                let returnParameter = JSON.stringify(res)
                let operationPicture = '成品入库'
                let callInterface = res.rquestUrl
                let opertionParmes = {
                  inputParameter,
                  returnParameter,
                  operationPicture,
                  responseCode: res.code, //返回状态
                  errorMessage: res.msg, //错误信息
                  isPass: res.code == 0 ? 'Y' : 'N', //是否成功 Y N
                  callInterface,
                  operationType: OPERATION_SCAN,
                  module: 'WMS',
                  source: "PDA",
                }
                basPdaOperationLogFn(opertionParmes)
              } catch (error) {
              }
              if (res.code == 0) {
                if (data.lockStatus != 'lock') {
                  uni.showToast({
                    title: t('mexico.unLockSuccess'),
                    icon: 'none'
                  })
                }
              } else {
                // 调用接口失败后还原
                data.isChecked = !data.isChecked
                uni.showToast({ title: res.msg, icon: 'none' })
              }
            })
          } else if (res.cancel) {
            // data.locationCode = ''
          }
        }
      });
      changeLocation()
    } else {
      uni.showToast({ title: res.msg, icon: "none" });
    }
  })
}


//扫描纪录
const clickRight = () => {
  navigate({
    url: '/pages/barcodeManagement/productInventoryRecord'
  })
}

//导航栏左侧返回
onBackPress((options) => {
  if (options.from == 'backbutton') {
    navBackCheck()
    return true;
  }
})

const clickLeftBack = () => {
  navBackCheck()
}
const navBackCheck = () => {
  if (!data.barcodeList.length && data.isChecked == false) {
    uni.navigateBack({
      delta: 1
    });
    return true
  } else if (data.isChecked) {
    uni.showModal({
      title: t('smashRemoval.warmPrompt'),
      content: t('taskList.unLockReturn'),
      success: function (res) {
        if (res.confirm) {
          let parmes = {
            locationCode: data.locationCode,
            lockStatus: 'unLock'
          }
          pdaLockLocation(parmes).then(res => {
            if (res.code == 0) {
              uni.navigateBack({
                delta: 1
              });
            } else {
              // 调用接口失败后还原
              data.isChecked = !data.isChecked
              uni.showToast({ title: res.msg, icon: 'none' })
            }
          })

        } else if (res.cancel) {
          console.log('用户点击取消');
        }
      }
    });
    return true
  }
  // 提示是否有未提交的数据
  uni.showModal({
    title: t('smashRemoval.warmPrompt'),
    content: t('materials.unsubmittedDataIn'),
    success: function (res) {
      if (res.confirm) {
        store.commit('reactFinishedProductStorage')
        uni.navigateBack({
          delta: 1
        });
      } else if (res.cancel) {
        console.log('用户点击取消');
      }
    }
  });
  return true
}
</script>

<style lang="scss" scoped>
.barcodeSplitting {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 88rpx);
  // height: 100vh;
}

.distributed-head {
  border-bottom-left-radius: 16rpx;
  border-bottom-right-radius: 16rpx;
}

.scroll {
  flex: 1;
  height: 2rpx;
}

.custom-card-itemTwo {
  position: relative;
}

.itemTwoMask {
  position: absolute;
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  z-index: 1;
}
</style>
